package pl.wroc.pwr.mss.logic.domain;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;


/**
 * Encja reprezentujaca playliste utworow muzycznych.
 * 
 * @author mjagus
 */
@Entity
@Table(name = "PLAYLISTS")
public class Playlist extends AbstractEntity implements Cloneable
{
    /**
     * Identyfikator klasy.
     */
    private static final long serialVersionUID = 4814067846113244131L;

    /**
     * Nazwa playlisty.
     */
    private String name;

    /**
     * Lista utworow nalezacych do playlisty.
     */
    private List<Song> songs;

    /**
     * @return Nazwa playlisty
     */
    @Column(name = "NAME")
    public String getName()
    {
        return name;
    }

    /**
     * @return Lista utworow nalezacych do playlisty
     */
    @OneToMany
    @JoinColumn(name = "PLAYLIST_ID")
    @Cascade(CascadeType.ALL)
    @Fetch(value = FetchMode.JOIN)
    @OrderBy(value = "priority")
    public List<Song> getSongs()
    {
        return songs;
    }

    /**
     * @param name Nazwa playlisty do ustawienia
     */
    public void setName(String name)
    {
        this.name = name;
    }

    /**
     * @param songs Lista utoworow do ustawienia
     */
    public void setSongs(List<Song> songs)
    {
        this.songs = songs;
    }

    @Override
    public Playlist clone()
    {
        Playlist clone = new Playlist();
        clone.setId(getId());
        clone.setName(getName());

        List<Song> songs = new ArrayList<Song>();
        songs.addAll(getSongs());
        clone.setSongs(songs);

        return clone;
    }
}
